﻿using ProductSystem.BLL;
using ProductSystem.BLL.Common;
using ProductSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ProductSystem.Web.Controllers
{
    public class OrderController : ManageControllerBase
    {
        #region 餐桌预订管理
        [ManageAuthorize(RequireCheckRole = true, ActionName = "Order-BookingList")]
        public ActionResult BookingList()
        {
            List<Booking> list = Booking_Bll.GetAllList();
            ViewData.Model = list;
            return View();
        }

        public ActionResult BookingAdd(string ids)
        {
            ViewData["DeskID"] = ids;
            return View();
        }

        [HttpPost]
        //[ManageAuthorize(RequireCheckRole = true, ActionName = "Order-BookingList")]
        public ActionResult BookingAdd(Booking model)
        {
            model.Status = 1;
            ReturnStatus rs = DataAddGeneric<Booking>.Add(model);
            Desk_Bll.UpdateDeskStatus(model.DeskID, Convert.ToInt32(DeskStatusEnum.Booked));
            return Json(rs, JsonRequestBehavior.AllowGet);
        }

        [ManageAuthorize(RequireCheckRole = true, ActionName = "Order-BookingList")]
        public ActionResult DelDeskType(String ids)
        {
            using (EntitiesModel dbContext = new EntitiesModel())
            {
                List<string> idList = ids.Split(',').ToList();
                var list = dbContext.DeskTypes.Where(o => idList.Contains(o.ID.ToString())).ToList();
                ReturnStatus rs = DeskType_Bll.DeleteDeskType(ids);
                return Json(rs, JsonRequestBehavior.AllowGet);
            }
        }
        #endregion
        #region 订单管理
        public ActionResult OrderAdd(int DeskID)
        {
            ViewData.Model = Booking_Bll.GetFoodList();
            return View();
        }
        #endregion
    }
}
